home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / MakeWrite / MakeWrite Folder / MWFontOps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-19  |  2.5 KB  |  132 lines  |  [TEXT/KAHL]

  1. # include    "TransSkel.h"
  2.  
  3. # include    "MakeWrite.h"
  4.  
  5.  
  6. /*
  7.  * Query user whether to replace the current font list with the
  8.  * selected font, or just add them to the list.  Return false if
  9.  * Cancel clicked.  If Replace clicked, then warn user that the
  10.  * map will be destroyed (if it has been changed) and return false
  11.  * if he declines.  Otherwise return true.
  12.  *
  13.  * If Replace is selected, then the map and the font list are
  14.  * cleared as well as setting some state variables.  The map is
  15.  * really modified by clearing it, but that was ok'd by user, so is
  16.  * now considered clean (unmodified) - just like after New Map.
  17.  */
  18.  
  19. static Boolean
  20. ReplaceOrAdd (void)
  21. {
  22. typedef enum    /* alert button numbers */
  23. {
  24.     cancel = 1,
  25.     add,
  26.     replace
  27. };
  28. short    i;
  29.  
  30.     i = SkelAlert (replaceAlrtNum, SkelDlogFilter (nil, true),
  31.                                             skelPositionOnParentDevice);
  32.     SkelRmveDlogFilter ();
  33.     SkelDoUpdates ();
  34.  
  35.     if (i == cancel)
  36.         return (false);
  37.  
  38.     if (i == replace)
  39.     {
  40.         if (!DestroyWarn ())
  41.             return (false);
  42.         ClobberMap ();
  43.         ClearMapName ();
  44.         ResetFontList ();
  45.         mapModified = false;
  46.         undoOp = noUndo;
  47.     }
  48.     return (true);
  49. }
  50.  
  51.  
  52. /*
  53.  * Add the names of the FONT resources in the open resource files
  54.  * to the font list (or replace the list with those fonts). */
  55.  
  56. void
  57. ResourceFonts (Boolean ask)
  58. {
  59. short    i;
  60. short    fNum, nFonts;
  61. Str255    fontName;
  62. MenuHandle    m;
  63.  
  64.     if (ask)
  65.     {
  66.         if (ReplaceOrAdd () == false)
  67.             return;
  68.     }
  69.  
  70.     m = NewMenu (tempMenuNum, "\p");
  71.     AddResMenu (m, 'FONT');
  72.     nFonts = CountMItems (m);
  73.     for (i = 1; i <= nFonts; ++i)
  74.     {
  75.         GetItem (m, i, fontName);
  76.         GetFNum (fontName, &fNum);
  77.         if (!SetFontSpec (fNum, fontName))
  78.             break;
  79.     }
  80.     SyncFontSpecs ();
  81. }
  82.  
  83.  
  84. /*
  85.  * Add the fonts contained in the STR# whose id is  fontStrNum
  86.  * to the font list (or replace the list with those fonts).
  87.  */
  88.  
  89. void
  90. StrFonts (Boolean ask)
  91. {
  92. Handle    h;
  93. short    i, j, len;
  94. short    nStrings;
  95. Str255    s;
  96. long    fNum;
  97.  
  98.     if (ask)
  99.     {
  100.         if (ReplaceOrAdd () == false)
  101.             return;
  102.     }
  103.  
  104.     h = GetResource ('STR#', fontStrNum);
  105.     nStrings = * (short *) *h;
  106.  
  107.     for (i = 0; i < nStrings; ++i)
  108.     {
  109.         GetIndString (s, fontStrNum, i + 1);
  110.         if (s[1] == '#')
  111.             continue;            /* comment - ignore */
  112.         len = s[0];
  113.         j = 1;
  114.         while (j <= len && s[j] != '/')
  115.             ++j;
  116.         if (j > len)    /* error */
  117.         {
  118.             NumToString ((long) fontStrNum, s);
  119.             Message3 ("\pA font list resource (STR# ", s,
  120.                         "\p) is messed up.");
  121.             break;
  122.         }
  123.         s[0] = j - 1;    /* length of numeric part */
  124.         StringToNum (s, &fNum);
  125.         s[j] = len - j;
  126.         if (!SetFontSpec ((short) fNum, &s[j]))
  127.             break;
  128.     }
  129.     ReleaseResource (h);
  130.     SyncFontSpecs ();
  131. }
  132.